package com.jiao.domain;

import com.jiao.domain.entity.SysUser;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@NoArgsConstructor
//@AllArgsConstructor 的作用复习
public class LoginUser implements UserDetails {

    private SysUser sysUser;

    //存储权限信息
    private List<String> permissions;

    public LoginUser(SysUser sysUser, List<String> permissions) {
        this.sysUser = sysUser;
        this.permissions = permissions;
    }

    //存储SpringSecurity所需要的权限信息的集合
//    @JSONField(serialize = false)
//    private List<GrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //把permissions中字符串类型的权限信息转换成GrantedAuthority对象存入authorities中
//        authorities = permissions.stream().
//                map(SimpleGrantedAuthority::new)
//                .collect(Collectors.toList());
        return null;
    }
    //这里传入的密码和用户名，会与在登录接口中把登录界面填写的账号和密码封装在Authentication里的数据，进行比对
    //如果这个账号和密码是对的，那么就会将这个对象传递给authenticate.getPrincipal()
    /*
    * 用户密码
    * */
    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }
    /*
     * 用户名
     * */
    @Override
    public String getUsername() {
        return sysUser.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}